package com.ds.service.impl;

import cn.hutool.core.util.RandomUtil;

import com.ds.datasource.DS;
import com.ds.datasource.DsConstant;
import com.ds.entity.Student;
import com.ds.mapper.StudentMapper;
import com.ds.service.IStudentService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学生实现类
 */
@Service
public class StudentServiceImpl implements IStudentService {

    @Autowired
    StudentMapper studentMapper;

    @DS(DsConstant.DS2)
    @Override
    public List<Student> findAll() {
        return studentMapper.selectAll();
    }

    @DS(DsConstant.DS2)
    @Override
    public void insert() {
        Student student = new Student();
        student.setStudentCode("Code-" + RandomUtil.randomNumber());
        student.setStudentCode("学员-" + RandomUtil.randomNumber());
        studentMapper.insertStudent(student);
        // 模拟业务异常，验证事务回滚
        // int k = 1 / 0;
    }
}
